package com.crl.gen.dao;

import com.crl.dao.BaseDao;
import com.crl.gen.model.GenConfig;
import com.crl.gen.vo.GenConfigSearchVO;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @description:
 * @author: 孔垂云
 * @version: 1.0
 * @date: 2020/7/22 23:02
 */
@Repository
public class GenConfigDao2 extends BaseDao<GenConfig, GenConfigSearchVO> {

    /**
     * 新增
     *
     * @param genConfig
     * @return
     */
    public int add(GenConfig genConfig) {
        String sql = "INSERT INTO td_gen_config(id,vue_filepath,java_api_filepath,java_biz_filepath,database_type,codemodel_filepath,author_name) " +
                "VALUES(seq_td_gen_config.nextVal,:vueFilepath,:javaApiFilepath,:javaBizFilepath,:databaseType,:codemodelFilepath,:authorName)";
        return insert(sql, genConfig);
    }


    /**
     * 修改
     *
     * @param genConfig
     * @return
     */
    public int update(GenConfig genConfig) {
        String sql = "UPDATE td_gen_config SET vue_filepath=:vueFilepath,java_api_filepath=:javaApiFilepath,java_biz_filepath=:javaBizFilepath,database_type=:databaseType,codemodel_filepath=:codemodelFilepath,author_name=:authorName WHERE id=:id";
        return update(sql, genConfig);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    public int delete(int id) {
        String sql = "DELETE FROM td_gen_config WHERE id=?";
        return delete(sql, id);
    }


    /**
     * 列表
     *
     * @return
     */
    public List<GenConfig> list() {
        String sql = "SELECT id,vue_filepath,java_api_filepath,java_biz_filepath,database_type,codemodel_filepath,author_name FROM td_gen_config WHERE 1=1 ";
        sql += " ORDER BY id ASC";
        return list(sql);
    }

    /**
     * 获取单个
     *
     * @param id
     * @return
     */
    public GenConfig get(int id) {
        String sql = "SELECT id,vue_filepath,java_api_filepath,java_biz_filepath,database_type,codemodel_filepath,author_name FROM td_gen_config WHERE id=?";
        return get(sql, id);
    }

}
